﻿@page "/tests/datagrid/virtualize/in-memory"
<Row>
    <Column>
        <Card Margin="Margin.Is4.OnY">
            <CardHeader>
                <CardTitle>Datagrid: Virtualize In Memory</CardTitle>
            </CardHeader>
            <CardBody>
                <Paragraph>
                    Set the <code>Virtualize</code> property to <code>true</code> to enable virtual scrolling in our Data Grid. The Data Grid
                    loads and renders only the data rows that become visible. You can also define <code>VirtualizeOptions</code> for
                    additional control over virtualize look and behaviour.
                </Paragraph>
                <Alert Color="Color.Info" Visible>
                    <AlertDescription>
                        Note that this mode requires that all rows have the same height.
                    </AlertDescription>
                </Alert>
                <Paragraph>
                    In this mode, the Data Grid does not display the pager.
                </Paragraph>
            </CardBody>
            <CardBody>
                <DataGrid TItem="Employee"
                          Data="inMemoryData"
                          Responsive
                          Virtualize
                          VirtualizeOptions="virtualizeOptions"
                          ShowPager
                          ShowPageSizes>
                    <DataGridColumns>
                        <DataGridColumn TextAlignment="TextAlignment.Center" TItem="Employee" Field="@nameof( Employee.Id )" Caption="#" Width="60px" />
                        <DataGridColumn TItem="Employee" Field="@nameof( Employee.FirstName )" Caption="First Name">
                        </DataGridColumn>
                        <DataGridColumn TItem="Employee" Field="@nameof( Employee.LastName )" Caption="Last Name" />
                        <DataGridColumn TItem="Employee" Field="@nameof( Employee.Email )" Caption="Email" />
                        <DataGridColumn TItem="Employee" Field="@nameof( Employee.City )" Caption="City">
                            <CaptionTemplate>
                                <Icon Name="IconName.City" /> @context.Caption
                            </CaptionTemplate>
                        </DataGridColumn>
                        <DataGridColumn TItem="Employee" Field="@nameof( Employee.Zip )" Caption="Zip">
                        </DataGridColumn>
                        <DataGridDateColumn TItem="Employee" Field="@nameof( Employee.DateOfBirth )" DisplayFormat="{0:dd.MM.yyyy}" Caption="Date Of Birth" Editable />
                        <DataGridNumericColumn TItem="Employee" Field="@nameof( Employee.Childrens )" Caption="Childrens" Editable Filterable="false" />
                        <DataGridSelectColumn TItem="Employee" Field="@nameof( Employee.Gender )" Caption="Gender" Editable Data="EmployeeData.Genders" ValueField="(x) => ((Gender)x).Code" TextField="(x) => ((Gender)x).Description" /><DataGridSelectColumn TItem="Employee" Field="@nameof( Employee.Gender )" Caption="Gender" Editable Data="EmployeeData.Genders" ValueField="(x) => ((Gender)x).Code" TextField="(x) => ((Gender)x).Description" />EmployeeData.Genders
                        <DataGridColumn TItem="Employee" Field="@nameof( Employee.Salary )" Caption="Salary" Editable Width="140px" DisplayFormat="{0:C}" DisplayFormatProvider="@System.Globalization.CultureInfo.GetCultureInfo("fr-FR")" TextAlignment="TextAlignment.End">
                        </DataGridColumn>
                        <DataGridCheckColumn TItem="Employee" Field="@nameof(Employee.IsActive)" Caption="Active" Editable Filterable="false">
                            <DisplayTemplate>
                                <Check TValue="bool" Checked="context.IsActive" Disabled ReadOnly />
                            </DisplayTemplate>
                        </DataGridCheckColumn>
                    </DataGridColumns>
                </DataGrid>
            </CardBody>
        </Card>
    </Column>
</Row>

@code {

    [Inject] EmployeeData EmployeeData { get; set; }

    private VirtualizeOptions virtualizeOptions;
    private IEnumerable<Employee> inMemoryData;

    protected override async Task OnInitializedAsync()
    {
        virtualizeOptions = new() { DataGridHeight = "500px" };
        inMemoryData = ( await EmployeeData.GetDataAsync() );
        await base.OnInitializedAsync();
    }
}